//获取数据
function get_apply(){
    var index1=layer.load(
        3,
        {shade:[0.5,'#000']}
    )
    $.post(
            "controler.php",
            {
                handle:"get_apply"
            },
            function (msg) 
            {   
                layer.close(index1);
                var data=JSON.parse(msg);
                var show_string="";

                for (let index = 0; index < data.length; index++) {
                    var mark='<span style="color:red;text-decoration: underline;cursor: pointer;" onclick="mark('+ "'" +  data[index]['id']  + "'" +')">点击标记</span style="color:red;">';
                    if(data[index]['mark']=="1"){
                        mark='<span style="color:green;">已联系</span>';
                    }
                    show_string=show_string +'<tr><td>' + data[index]['name'] + '</td><td>' + data[index]['destination'] + '</td><td>' + data[index]['phone'] + '</td><td>' + data[index]['email'] + '</td><td>' + data[index]['wechat'] + '</td><td>' + data[index]['time'] + '</td><td>'+ mark +'</td><td><button onclick="dele('+ "'" +  data[index]['id']  + "'" +')">删除</button></td></tr>';
                }
                show_string= '<tr><th>姓名</th><th>目的地</th><th>手机</th><th>电子邮箱</th><th>微信号</th><th>申请时间</th><th>已联系</th><th>删除</th></tr>'+ show_string;
                $(".apply_table").html(show_string);
    });
}
//标记数据
function mark(id){
    var index1=layer.load(
        3,
        {shade:[0.5,'#000']}
    )
    $.post(
            "controler.php",
            {
                handle:"mark_apply",
                id:id
            },
            function (msg) 
            {
                layer.close(index1);
                result(msg);
    });
}
//删除数据
function dele(id){
    layer.confirm('确定要删除此记录吗？', {icon: 3, title:'提示'}, function(index){
    layer.close(index);
    var index1=layer.load(
        3,
        {shade:[0.5,'#000']}
    )
    $.post(
            "controler.php",
            {
                handle:"dele_apply",
                id:id
            },
            function (msg) 
            {
                layer.close(index1);
                result(msg);
        });
    });
}

function result(msg){
    try {
        var data=JSON.parse(msg);
        if(data.code=="done"){
            get_apply();
        }
        else{
            layer.alert(data.msg);
        }
    } catch(e) {
        layer.alert("请求出错，请稍后再试！");
    }
}